<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	
	<!--导入插件-->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="area.js"></script>
	<script type="text/javascript" src="location.js"></script>

		<!--层级联动选择框-->
	<select id="loc_province" class="" name="sheng" style="width:80px;"></select>
	<select id="loc_city" class="" name="shi" style="width:100px;"></select>
	<select id="loc_town" class="" name="xian" style="width:120px;"></select>
	

	<script type="text/javascript">
	$(document).ready(function() {
		showLocation();
		$('#addresses .attr').each(function(){
			var str = $(this).attr('attr');
			var info = getInfo(str);
			$(this).html(info);
		});

		//定义获取城市信息方法
		function getInfo(str){
			//console.log(str);
			//拆分字符串
			var arr = str.split(',');
			// console.log(arr);	
			var ls  = new Location;
			var l = ls.items;
			// console.log(l['0,1,2']['5']);
			var sheng = l['0'][arr[0]];
			var shi = l['0,'+arr[0]][arr[1]];
			var xian = l['0,'+arr[0]+','+arr[1]][arr[2]];
			return sheng+shi+xian;
		}

		//点击选中默认地址
		$('#addresses .item').each(function(){
			$(this).click(function(){
				//
				$('#addresses .item').removeClass('aa');	
				$(this).addClass('aa');
				//获取当前点击的地址id
				var id  = $(this).attr('aid');	
				$('input[name=address_id]').val(id);
			})
		})				
	});
	</script>

</body>
</html>